<?php

namespace app\admin\model\grade;

use think\Model;


class Grade extends Model
{

    // 表名
    protected $name = 'grade';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public function get_grade($grade)
    {
        $str = str_replace("#","",$grade);
        $ids = explode(',',$str);
        $grade = collection(model("\app\admin\model\teacher\grade")->where(['id'=>['in',$ids]])->column('grade_title','id'))->toArray();
        return $grade;
    }

    //获取列表
    public function getGradeList(){
		return collection(self::where('status', 0)->order('id asc')->select())->toArray();
	}
    
    //获取名称
    public function getgradeInfo($data = array()){

        if(empty($data)){
            return false;
        }
        $list = array();
        //判断是否多行
        if(strstr($data, ',')){
            $gradeids = array_filter(explode(',',$data));
            foreach($gradeids as $key=>$value){
                $list[$key]['id'] = $value;
                $list[$key]['grade_title'] = self::where('id',$value)->value('grade_title');
            }
        }else{
            $list[0]['id'] = $data;
            $list[0]['grade_title'] = self::where('id',$data)->value('grade_title');
        }

        return $list;
       
    }
}
